package com.wxzz.elearing.course.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxzz.elearing.course.entity.WxUserCurriculumSection;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Optional;

/**
 * <p>
 * 我的测试 Mapper 接口
 * </p>
 *
 * @author
 * @since 2021-03-15
 */
public interface WxUserCurriculumSectionMapper extends BaseMapper<WxUserCurriculumSection> {

    @Select("SELECT * FROM `wx_user_curriculum_section` WHERE curriculum_section_id = #{curriculumSectionId} AND wx_user_id = #{wxUserId} AND deleted = 0")
    Optional<WxUserCurriculumSection> selectWxUserCurriculumSection(@Param("curriculumSectionId") Long curriculumSectionId, @Param("wxUserId") Long wxUserId);

    @Select("SELECT\n" +
            "\tCOUNT( 1 ) \n" +
            "FROM\n" +
            "\t`wx_user_curriculum_section` \n" +
            "WHERE\n" +
            "\twx_user_id = #{wxUserId} AND curriculum_id = #{curriculumId}\n" +
            "\tAND curriculum_section_id = #{curriculumSectionId} \n" +
            "\tAND is_pass = 1 \n" +
            "\tAND deleted = 0")
    Integer countWxUserCurriculumSectionPassNum(@Param("wxUserId") Long wxUserId, @Param("curriculumSectionId") Long curriculumSectionId,@Param("curriculumId")Long curriculumId);

}
